import pymysql

def main():
    conn = pymysql.connect(host='127.0.0.1',port=3306, user='root', password='root',db='dhd',charset='utf8')
    try:
        with conn.cursor() as cursor:
            a = cursor.execute('select * from user where id = %s',1)
            print(a)
            conn.commit()
    except Exception as error:
        print(error)
        conn.rollback()
    finally:
        conn.close()
if __name__ == '__main__':
    main()